﻿using System;
using System.Web;

using SBPweb.PROvibe.Server.Core;
using SBPweb.PROvibe.Server.Core.Events;
using SBPweb.PROvibe.Server.Library.Events;

namespace SBPweb.PROvibe.Server.Host
{

    public class Global : HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            LogManager.Logger = LogEventsManager.CreateLogManagerInstance();
            ServerContext.Instance.Initialize();
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            LogManager.Logger.WriteVerbose(sender, string.Format("Session started with id {0}.", Session.SessionID), LogManager.Categories.Server.Host);
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {
            if (LogManager.Logger != null && LogManager.Logger.IsInitialized)
            {
                Exception ex = Context.Server.GetLastError();
                LogManager.Logger.WriteError(this, ex, LogManager.Categories.Server.Host);
            }
        }

        protected void Session_End(object sender, EventArgs e)
        {
            LogManager.Logger.WriteVerbose(sender, string.Format("Session end with id {0}.", Session.SessionID), LogManager.Categories.Server.Host);
        }

        protected void Application_End(object sender, EventArgs e)
        {

        }

    }

}